<!DOCTYPE html>
<html>
	<head>
		<base href="{$base_name}"/>
		<meta charset="utf-8" />
		<meta content="yes" name="apple-touch-fullscreen">
		<meta content="yes" name="apple-mobile-web-app-capable">
        <meta content="telephone=no,email=no" name="format-detection">
		<script type="text/javascript" src="libs/flexible_css.js"></script>
		<script type="text/javascript" src="libs/config.js"></script>
		<script type="text/javascript" src="libs/flexible.js"></script>
		<link rel="stylesheet" type="text/css" href="css/details.css">
		<script type="text/javascript" src="libs/jquery-1.7.2.min.js"></script>
		<!-- <script type="text/javascript" src="js/exam.js"></script> -->
	</head>
	<body>
		<div id="container">
			
		</div>
	</body>
</html>
<script id="tpl" type="text/html">
<div class="question">
	<p>{{ d.num }}.{{ d.title }}</p>
</div>
<div class="choice">
	<div class="option">
		<ul>
			{{# for(var i = 0, len = d.list.length; i < len; i++){ }}
			<li data-num="{{ d.list[i].key }}">{{ d.list[i].value }}</li>
			{{# } }}
		</ul>
	</div>
</div>
</script>
<script src="./layui/laytpl.js"></script>
<script>
function get_json_page(){
	$.getJSON(root+'/class/test/?id='+id, function(data){
		g_data = data.data;
		total = g_data.length;
		tpl_data();
	});
}
function tpl_data(){
	if(cur_num >= total){
		//alert('已经是最后一道题');
		//进入计算页面
		localStorage.answer = answer;
		location.href = 'result.html?id='+id
		return false;
	}
	$('#container div').remove();
	var content = JSON.parse(g_data[cur_num].content);
	g_data[cur_num]['list'] = new Array();
	$.each(content,function(key,value){  
		//console.log("Obj :" + key + '-' + value);
		var list = new Array();
		list['key'] = key;
		list['value'] = value;
		g_data[cur_num]['list'].push(list);
	})
	
	g_data[cur_num]['num'] = cur_num+1;
	var tabtpl = $('#tpl').html();
	laytpl(tabtpl).render(g_data[cur_num], function(html){
		$('#container').append(html);
	});
	cur_num++;
	$('#container').append('<div class="next">下一题</div><div class="page">（第'+cur_num+'题/共'+total+'题）</div>');
}

var g_data = [];
var cur_num = 0;
//取得id值
var id = {$id};
var answer = '';
localStorage.answer = '';
//删除所有li
//$('#container').remove();
get_json_page();
var total = 0;


$('#container li').live('click',function(){
	$('#container li').removeClass('sel');
	$(this).addClass('sel');
});
$('.next').live('click',function(){
	//判断 有没有选上了
	var num = $('li[class="sel"]').attr('data-num');
	if(num == null || num == 'undefined'){
		alert('请选上您认为正确的答案');
		//进入计算页面
		return false;
	}
	if(answer == ''){
		answer = num;
	}else{
		answer += ','+num;
	}
	tpl_data();
});
</script>
